//: Playground - noun: a place where people can play

import Cocoa

extension Array {
    subscript(input: [Int]) -> ArraySlice<Element> {
        
        get {
            var result = ArraySlice<Element>()
            for i in input {
                assert(i < self.count, "Index out of range")
                result.append(self[i])
            }
            return result
        }
        
        set {
            for (index, i) in input.enumerated() {
                assert(i < self.count, "Index out of range")
                self[i] = newValue[index]
            }
        }
    }
}

//var array = [1, 2, 3, 4, 5]
//array[[0, 2, 3]]
//
//array[[0, 2, 3]] = [-1, -3, -4]
//
//print(array)
//
//print(array.enumerated())


// MARK: typealias

//func distance(from point: CGPoint, to anotherPoint: CGPoint) -> Double {
//    let dx = Double(anotherPoint.x - point.x)
//    let dy = Double(anotherPoint.y - point.y)
//    return sqrt(dx * dx + dy * dy)
//}
//
//let origin: CGPoint = CGPoint(x: 0, y: 0)
//let point: CGPoint = CGPoint(x: 1, y: 1)
//
//let d = distance(from: origin, to: point)


typealias Location = CGPoint
typealias Distance = Double

func distance(from location: Location, to anotherLocation: Location) -> Distance {
    let dx = Distance(location.x - anotherLocation.x)
    let dy = Distance(location.y - anotherLocation.y)
    return sqrt(dx * dx + dy * dy)
}

let origin = Location(x: 0, y: 0)
let point = Location(x: 1, y: 1)

let d = distance(from: origin, to: point)

class Person<T> {}
typealias Worker<T> = Person<T>

protocol Cat {}
protocol Dog {}
typealias Pat = Cat & Dog



